package com.gs.SynPatrolRep.presenter;


import com.google.gson.reflect.TypeToken;
import com.gs.SynPatrolRep.apiresult.ApiResultData;
import com.gs.SynPatrolRep.apiresult.PagedList;
import com.gs.SynPatrolRep.db.dto.CancelPalBillDto;
import com.gs.SynPatrolRep.db.dto.PalBillListDto;
import com.gs.SynPatrolRep.db.query.BaseQuery;
import com.gs.SynPatrolRep.model.listener.OnResultListener;
import com.gs.SynPatrolRep.model.PalBillModel;
import com.gs.SynPatrolRep.view.IPalBillListView;

public class PalBillListPresenter extends BasePresenter<IPalBillListView> {
    private PalBillModel palBillModel = new PalBillModel();

    public void getData(BaseQuery query,String url) {
        palBillModel.getPalBills(query,url,new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onGetDataSuccess((ApiResultData<PagedList<PalBillListDto>>) apiResult);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onGetDataFails(e);
                }
            }
        }, new TypeToken<ApiResultData<PagedList<PalBillListDto>>>() {
        }.getType());
    }

    public void cancel(CancelPalBillDto bean, int position) {
        getView().showLoading();
        palBillModel.cancel(bean, new OnResultListener() {
            @Override
            public void onSuccess(Object aipResult) {
                if (getView() != null) {
                    getView().hideLoading();
                    getView().onCancelSuccess((ApiResultData<String>) aipResult,position);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().hideLoading();
                    getView().onCancelFails(e);
                }
            }
        }, new TypeToken<ApiResultData<String>>() {
        }.getType());
    }

}
